#include "protocol.h"
#include "babel.h"
#include "ui_babel.h"

void CSProtocol::AddContact::sendTreat(TCPClient &connexion)
{
    (void)connexion;
    CSProtocol::Header header = CSProtocol::Header();
    header.code = CSProtocol::AddContact::code;
    header.dataLength = sizeof(CSProtocol::AddContact);
    header.spontaneous = false;

    QString qLogin = dynamic_cast<Babel*>(connexion.parent()->parent())->ui->addcontact->text();
    QString qCategory = dynamic_cast<Babel*>(connexion.parent()->parent())->ui->addcontactcategory->text();
    strcpy(this->login, qLogin.toStdString().c_str());
    strcpy(this->category, qCategory.toStdString().c_str());
    connexion.writeData(header, this);
}

void CSProtocol::AddContact::receiveTreat(TCPClient &connexion, IData *data)
{
    Babel * window = dynamic_cast<Babel *>(connexion.parent()->parent());
    (void)window;
    CSProtocol::Header *header = connexion.getReadingHeader();
    if (header->code == CSProtocol::Ok::code)
    {
        qDebug() << (static_cast<CSProtocol::Ok*>(data))->what;
    }
    else
    {
        qDebug() << (static_cast<CSProtocol::Ok*>(data))->what;
    }
}
